//
//  UIButton+Extension.swift
//  微博
//
//  Created by 王朝阳 on 16/4/7.
//  Copyright © 2016年 王朝阳. All rights reserved.
//

import UIKit

extension UIButton {
    
    /// 按钮设置图片便利构造函数
    convenience init(imageName: String, backImageName: String) {
        self.init()
        
        setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
        setBackgroundImage(UIImage(named: backImageName), forState: UIControlState.Normal)
        setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: UIControlState.Highlighted)
        
        // 会根据背景图片的大小调整尺寸
        sizeToFit()
        
        
    }
    /// 标题，图片
    convenience init (title: String, color:UIColor, backgroundImage: String)
    {
        self.init()
        setTitle(title, forState: .Normal)
        setTitleColor(color, forState: .Normal)
        setBackgroundImage(UIImage(named: backgroundImage), forState: .Normal)
    }
    
}
